#include "../src/dot.cpp"

// CppUnit headers
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>

#include <cppunit/CompilerOutputter.h>

// C++ headers
#include <string>

class DotTest : public CppUnit::TestFixture
{
    CPPUNIT_TEST_SUITE(DotTest);

    // Test cases
    CPPUNIT_TEST(testCase);

    CPPUNIT_TEST_SUITE_END();

// public constructors & destructor
public:
    DotTest(void);
    virtual ~DotTest(void);

// setUp & tearDown
public:
    virtual void setUp(void);
    virtual void tearDown(void);

// test cases
private:
    //void testSample(void);
    void testCase(void);

// private constructors & destructor
private:
    // Disable the evil constructor and assignment operator.
    DotTest(const DotTest&);
    DotTest& operator=(const DotTest&);
};

CPPUNIT_TEST_SUITE_REGISTRATION(DotTest);

DotTest::DotTest(void)
{
}

DotTest::~DotTest(void)
{
}

void DotTest::setUp(void)
{
}

void DotTest::tearDown(void)
{
}

void DotTest::testCase(void)
{
    Dot dot;
    dot.move();
}

int main(int argc, char* argv[])
{
    CppUnit::TextUi::TestRunner runner;
    std::string format = CPPUNIT_COMPILER_LOCATION_FORMAT;
    size_t state = 0;
    for (std::string::size_type i = 0; i < format.size(); ++i)
    {
        if (state == 0 &&format[i] == '%')
        {
            state = 1;
        }
        else
        {
            if (format[i] == 'f')
                format[i] = 'p';
            state = 0;
        }
    }
    CppUnit::CompilerOutputter* outputter =
        new CppUnit::CompilerOutputter(&runner.result(),
                                       std::cout,
                                       format.c_str());
    runner.setOutputter(outputter);
    CppUnit::TestSuite* suite = new CppUnit::TestSuite();
    CppUnit::TestFactoryRegistry& registry =
        CppUnit::TestFactoryRegistry::getRegistry();
    runner.addTest(registry.makeTest());
    runner.addTest(suite);
    return runner.run("", false) ? 0 : 1;
}
